package com.goldsign.pay.provider.msg.rabbit.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**订阅模式*/
@Configuration
public class RabbitFanoutConfig {
	final String messageA = "dev.fanout.A";
    final String messageB = "dev.fanout.B";
    final String messageC = "dev.fanout.C";
    final String fanoutExchange = "dev.fanoutExchange";
    
    @Bean
    public Queue messageFanoutA() {
        return new Queue(messageA);
    }
    
    @Bean
    public Queue messageFanoutB() {
        return new Queue(messageB);
    }
    
    @Bean
    public Queue messageFanoutC() {
        return new Queue(messageC);
    }
    
    /**新建交换机*/
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(fanoutExchange);
    }
    
    /**再把这些队列绑定到交换机上去*/
    @Bean
    Binding bindingExchangeA(Queue messageFanoutA, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(messageFanoutA).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeB(Queue messageFanoutB, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(messageFanoutB).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeC(Queue messageFanoutC, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(messageFanoutC).to(fanoutExchange);
    }
    
}
